package com.cat.chapter043;

import java.io.*;

/**
*   @description https://www.nowcoder.com/practice/d88ef50f8dab4850be8cd4b95514bbbd
*   @author cat
*   @create 2025/7/12 14:56
*   @since JDK17
*/

public class Solution01 {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter pr = new PrintWriter(new OutputStreamWriter(System.out));
    static StreamTokenizer st = new StreamTokenizer(br);
    static int[] doub = new int[12];
    static int[] hurt = new int[12];

    public static void swap(int i, int j) {
        int t = hurt[i];
        hurt[i] = hurt[j];
        hurt[j] = t;

        t = doub[i];
        doub[i] = doub[j];
        doub[j] = t;
    }

    public static int f(int cur, int n, int blood) {
        if (blood <= 0) {
            return cur;
        }
        if (cur == n) {
            return Integer.MAX_VALUE;
        }
        int ans = Integer.MAX_VALUE;
        for (int i = cur; i < n; i++) {
            swap(cur, i);
            f(cur + 1, n, blood - (blood <= doub[i] ? hurt[i] * 2 : hurt[i]));
            swap(cur, i);
        }
        return ans;
    }


    public static void main(String[] args) throws IOException {
        st.nextToken();
        int n = ((int) st.nval);

        for (int i = 0; i < n; i++) {
            int total, blood;
            st.nextToken();
            total = ((int) st.nval);
            st.nextToken();
            blood = ((int) st.nval);
            for (int j = 0; j < total; j++) {
                st.nextToken();
                hurt[j] = ((int) st.nval);
                st.nextToken();
                doub[j] = ((int) st.nval);
            }
        }
    }
}
